define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'budget/summary/index' + location.search,
                    add_url: 'budget/summary/add',
                    del_url: 'budget/summary/del',
					export_url: 'budget/summary/export',
                    table: 'budget_summary',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
				search: false,
				searchFormVisible: true,
				rowStyle:function(row,index){
					if(index%2 == 0)
					{
						return {css: {"background-color": "#c3ebd1"}};
					}
					else
					{
						return '';
					}
				},
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('序号'), sortable: true, searchable: false, formatter: function(value, row, index){
							var pageNumber = table.bootstrapTable('getOptions').pageNumber;
							var pageSize = table.bootstrapTable('getOptions').pageSize;
							return ++index + (pageNumber-1)*pageSize;
						}},
						{field: 'budgetname', title: __('预算名称'), operate: 'LIKE'},
						{field: 'budgettime', title: __('预算时间（年）'), formatter: Table.api.formatter.datetime, addclass: 'datetimepicker', extend: "data-date-format='YYYY' data-use-current=true", datetimeFormat:'YYYY', sortable: true},
						{field: 'budgettype', title: __('预算类型'), searchList:{1: __('基本预算'), 2: __('项目预算')}, formatter: Table.api.formatter.label},
						//{field: 'createtime', title: __('生成时间'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
                        {field: 'status', title: __('完成情况'), searchList:{0: __('未完成'), 1: __('已完成')}, formatter: Table.api.formatter.normal},				
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, buttons:[
								{
									name: 'export',
									title: __('导出'),
									text:__('导出'),
									classname: 'btn btn-xs btn-primary',
									url: $.fn.bootstrapTable.defaults.extend.export_url
								}
							],formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
		add: function () {
			$(document).on('click','button[type="reset"]', function(){
				var index = parent.Layer.getFrameIndex(window.name);
				parent.Layer.close(index);
			});	
			
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});